//
//  ZZLogoutView.m
//  ZuZuBao
//
//  Created by Felix on 2024/4/15.
//

#import "ZZLogoutView.h"

@implementation ZZLogoutView

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        UIView * backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        backView.backgroundColor = kRGBAColor(0x000000, 0.6);
        [self addSubview:backView];
        
        UIView * wView = [[UIView alloc] initWithFrame:CGRectMake(43, kScreenHeight / 2 - 96, kScreenWidth - 86, 192)];
        wView.backgroundColor = [UIColor whiteColor];
        wView.layer.cornerRadius = 12;
        wView.layer.masksToBounds = YES;
        [self addSubview:wView];
        
        UILabel * cLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 29, wView.frame.size.width, 18)];
        cLabel.textColor = k333Color;
        cLabel.font = [UIFont systemFontOfSize:16];
        cLabel.textAlignment = NSTextAlignmentCenter;
        cLabel.text = @"温馨提示";
        [wView addSubview:cLabel];
        
        UILabel * loLabel = [[UILabel alloc] initWithFrame:CGRectMake(17, CGRectGetMaxY(cLabel.frame) + 16, wView.frame.size.width - 34, 48)];
        loLabel.textColor = k666Color;
        loLabel.font = [UIFont systemFontOfSize:16];
        loLabel.textAlignment = NSTextAlignmentCenter;
        loLabel.numberOfLines = 2;
        loLabel.text = @"账号注销后数据将不可恢复，确定要注销该账户？";
        [wView addSubview:loLabel];
        
        CGFloat width = (wView.frame.size.width - 17*3) / 2;
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(17, CGRectGetMaxY(loLabel.frame) + 26, width, 42);
        button.backgroundColor = kRGBAColor(0xECECEC, 1);
        button.layer.cornerRadius = 21;
        button.layer.masksToBounds = YES;
        [button setTitleColor:k333Color forState:UIControlStateNormal];
        [button setTitle:@"取消" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        [button addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
        [wView addSubview:button];
        
        UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom];
        button2.frame = CGRectMake(CGRectGetMaxX(button.frame) + 17, CGRectGetMaxY(loLabel.frame) + 26, width, 42);
        button2.backgroundColor = kRGBAColor(0xECECEC, 1);
        button2.layer.cornerRadius = 21;
        button2.layer.masksToBounds = YES;
        button2.layer.borderColor = k333Color.CGColor;
        button2.layer.borderWidth = 1;
        [button2 setTitleColor:k333Color forState:UIControlStateNormal];
        [button2 setTitle:@"确认" forState:UIControlStateNormal];
        button2.titleLabel.font = [UIFont systemFontOfSize:16];
        [button2 addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
        [wView addSubview:button2];
        
    }
    return self;
}

- (void)cancelAction {
    [self removeFromSuperview];
}

- (void)confirmAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickToLogout)]) {
        [self.delegate clickToLogout];
    }
    [self removeFromSuperview];
}

@end
